@extends('admin.base')

@section('content')
    <style>
        .layui-form-checkbox span{width: 100px}
    </style>
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <h2>管理员【{{$user->name}}】分配角色</h2>
        </div>
        <div class="layui-card-body">
            <form class="layui-form"  method="post">
                {{csrf_field()}}
                <div class="layui-form-item">
                    <label for="" class="layui-form-label">角色</label>
                    <div class="layui-input-block" style="width: 400px">
                        @forelse($roles as $role)
                            <input type="checkbox" name="roles[]" value="{{$role->id}}" title="{{$role->display_name}}" {{ $role->own ? 'checked' : ''  }} >
                        @empty
                            <div class="layui-form-mid layui-word-aux">还没有角色</div>
                        @endforelse
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 30px">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn layui-btn-normal" lay-submit  lay-filter="*"  lay-filter="formDemo">确 认</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('script')
    <script>
        layui.use('form', function(){
            var form = layui.form;
            form.on('submit(*)', function(data){
                http.post('{{route('system.user.assignRole',['user'=>$user])}}',data.field,function (res){
                    layer.msg('操作成功！', {icon: 1});
                    setTimeout(function () {
                        parent.location.reload();
                    },1000);
                })
                return false;
            });
        });
    </script>
@endsection

